package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyDingdingDayAttend;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyDingdingDayAttendParam;
import cn.stylefeng.guns.sys.modular.system.service.BtyDingdingDayAttendService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;


/**
 * 钉钉;前三十天，人员出勤数据控制器
 *
 * @author wjk
 * @Date 2022-05-30 17:16:47
 */
@Controller
@RequestMapping("/btyDingdingDayAttend")
public class BtyDingdingDayAttendController extends BaseController {

    private String PREFIX = "/modular/system/btyDingdingDayAttend";

    @Autowired
    private BtyDingdingDayAttendService btyDingdingDayAttendService;

    /**
     * 跳转到主页面
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyDingdingDayAttend.html";
    }

    /**
     * 月度详情
     * @param id
     * @param date
     * @param model
     * @return
     */
    @RequestMapping(value = "/monDetail_view/{id}/{date}")
    public String monDetail_view(@PathVariable String id, @PathVariable String date, Model model) {
        model.addAttribute("empId", id);
        model.addAttribute("attendYearMonth", date);
        return PREFIX + "/btyDingdingDayAttend.html";
    }
    /**
     * 新增页面
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyDingdingDayAttend_add.html";
    }

    /**
     * 编辑页面
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyDingdingDayAttend_edit.html";
    }

    /**
     * 新增接口
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyDingdingDayAttendParam btyDingdingDayAttendParam) {
        this.btyDingdingDayAttendService.add(btyDingdingDayAttendParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyDingdingDayAttendParam btyDingdingDayAttendParam) {
        this.btyDingdingDayAttendService.update(btyDingdingDayAttendParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyDingdingDayAttendParam btyDingdingDayAttendParam) {
        this.btyDingdingDayAttendService.delete(btyDingdingDayAttendParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyDingdingDayAttendParam btyDingdingDayAttendParam) {
        BtyDingdingDayAttend detail = this.btyDingdingDayAttendService.getById(btyDingdingDayAttendParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyDingdingDayAttendParam btyDingdingDayAttendParam) {
        return this.btyDingdingDayAttendService.findPageBySpec(btyDingdingDayAttendParam);
    }


    /**
     * 开始同步半天妖部门的员工的月度考勤信息
     * 月度,每一天的数据
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/addBtyDingdingDayAttend")
    @ResponseBody
    public ResponseData addDgdDingdingDayAttend(@RequestBody BtyDingdingDayAttendParam btyDingdingDayAttendParam) throws InterruptedException {
        Map<String,String> map = this.btyDingdingDayAttendService.addBtyDingdingDayAttend(btyDingdingDayAttendParam);
        return ResponseData.success(map);
    }

    @RequestMapping("/calculateAttendanceDays")
    @ResponseBody
    public ResponseData calculateAttendanceDays() {
        BtyDingdingDayAttend bold = this.btyDingdingDayAttendService.getById(2206080523362100014L);
        BtyDingdingDayAttend bnew= this.btyDingdingDayAttendService.calculateAttendanceDays(bold);
        return ResponseData.success(bnew);
    }
}


